#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 1e5+10;

int tr[N],pnum,prime[N],g[N],mu[N],ans[N];
bool v[N];
pii f[N];
struct Query{int n,m,a,id;}query[N];
bool operator < (Query x,Query y){return x.a < y.a;}

void add(int x,int y){for(;x<N;x+=x&-x)tr[x]+=y;}
int sum(int x,int y = 0){for(;x;x-=x&-x)y+=tr[x];return y;}

void init(){
	f[1] = pii(1,1); mu[1] = 1;
	for(int i = 2;i < N;i++){
		if(!v[i]){g[i] = f[i].fi = i + 1; prime[++pnum] = i; f[i].se = i;mu[i] = -1;}
		for(int j = 1,x;j <= pnum && prime[j] * i < N;j++){
			v[x = prime[j] * i] = 1;
			if(i % prime[j] == 0){g[x] = g[i] * prime[j] + 1; f[x].fi = f[i].fi / g[i] * g[x]; mu[x] = 0; f[x].se = x;break;}
			g[x] = prime[j] + 1; f[x].fi = f[i].fi * (prime[j] + 1); mu[x] = -mu[i]; f[x].se = x;
		}
	}
}

int solve(int n,int m){
	if(n > m) swap(n,m);int ans = 0;
	for(int l = 1,r;l <= n;l = r+1){
		r = min(n/(n/l),m/(m/l));
		ans += (n/l) * (m/l) * (sum(r) - sum(l-1));
	}return ans;
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	init(); sort(f+1,f+N);
	int q = in; for(int i = 1;i <= q;i++) query[i].n = in,query[i].m = in,query[i].a = in,query[i].id = i;
	sort(query+1,query+q+1);
	for(int i = 1,j = 1;i <= q;i++){
		while(j < N && f[j].fi <= query[i].a){
			//cout<<f[j].fi <<" "<<f[j].se<<endl;
			for(int k = f[j].se;k < N;k += f[j].se) add(k,f[j].fi * mu[k/f[j].se]);
			j++;
		}ans[query[i].id] = solve(query[i].n,query[i].m);
	}
	for(int i = 1;i <= q;i++) printf("%d\n",ans[i]&(~(1<<31)));
	return 0;
}

